/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package modele;

import parismetro.Cart;

/**
 * @author Hadrien
 */

public class OrderList {
    public var orders:Order[] on replace {doTotal();};
    public var total:Number;
    var observateurs:Cart[];

    public function addObservateur(cart:Cart){
        insert cart into observateurs;
    }

    public function doTotal() {
        var t = 0.;
        for (order in orders) {
            t += order.subTotal;
        }
        total = t;
        for (obs in observateurs) {obs.doGroupAchat();}
    }
    public function deliver() {
        for(order in orders) {
            order.deliver();
        }
    }
    public function countOrder():Integer {
        return orders.size();
    }
    public function addOrder(order:Order) {
        insert order into orders;
    }
    public function removeOrder(order:Order) {
        delete order from orders;
    }
    public function removeLast() {
        delete orders[orders.size()-1];
    }
    public function removeAll(){
        delete orders;
    }
    public bound function getLast(){
        return orders[orders.size()-1];
    }

}
